﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: ObjectNotificationEventArgs.cs
//
//  Description: EventArgs used in the IObjectNotification interface.
// 
//--------------------------------------------------------------------------

using System;
using System.Reflection;
using Chili.Opf3.Query;

namespace Chili.Opf3
{
	/// <summary>
	/// EventArgs used in the
	/// <see cref="Opf3.IObjectNotification">IObjectNotification</see> interface.
	/// </summary>
	/// <remarks>
	/// This EventArgs class is used by the
	/// <see cref="Opf3.IObjectNotification">IObjectNotification</see> interface to send
	/// additional event data. The data that is passed contains the
	/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation. The
	/// <see cref="Opf3.ObjectInfo">ObjectInfo</see> object that contains information about the
	/// state of the object and the <see cref="Opf3.Query.IQuery">IQuery</see> itself. 
	/// The <see cref="Opf3.Query.IQuery">IQuery</see> can be null if the object is loaded 
	/// from the storage.
	/// </remarks>
	[Serializable]
	public class ObjectNotificationEventArgs : EventArgs
	{
		private ObjectInfo _objectInfo;
		private ObjectContext _context;
		private IQuery _query;
		private PersistentOperations _operation;
		private PersistDepths _persistDepth;

		/// <summary>
		/// Creates a new instance of the
		/// <see cref="ObjectNotificationEventArgs">ObjectNotificationEventArgs Class</see>.
		/// </summary>
		/// <param name="objectInfo">
		/// 	<see cref="Opf3.ObjectInfo">ObjectInfo</see> that contains state informations of
		/// the persistent object that implements the
		/// <see cref="IObjectNotification">IObjectNotification</see> interface.
		/// </param>
		/// <param name="context"><see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.</param>
		/// <param name="operation">Specifies the current operation on the persistent object.</param>
		/// <exception cref="ArgumentNullException">ObjectInfo is null or context is null.</exception>
		/// <param name="persistDepth">Specifies the depth of the current persist operation.</param>
		internal ObjectNotificationEventArgs(ObjectInfo objectInfo, ObjectContext context, PersistentOperations operation, PersistDepths persistDepth)
		{
			if (objectInfo == null)
				throw new ArgumentNullException("objectInfo");
			if (context == null)
				throw new ArgumentNullException("context");

			_operation = operation;
			_objectInfo = objectInfo;
			_context = context;
			_persistDepth = persistDepth;
		}

		/// <summary>
		/// Creates a new instance of the
		/// <see cref="ObjectNotificationEventArgs">ObjectNotificationEventArgs Class</see>.
		/// </summary>
		/// <param name="query"><see cref="Opf3.Query.IQuery">IQuery</see> of the current operation.</param>
		/// <param name="objectInfo">
		/// 	<see cref="Opf3.ObjectInfo">ObjectInfo</see> that contains state informations of
		/// the persistent object that implements the
		/// <see cref="IObjectNotification">IObjectNotification</see> interface.
		/// </param>
		/// <param name="context"><see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.</param>
		/// <param name="operation">Specifies the current operation on the persistent object.</param>
		/// <exception cref="ArgumentNullException">Query is null, objectInfo is null or context is null.</exception>
		/// <param name="persistDepth">Specifies the depth of the current persist operation.</param>
		internal ObjectNotificationEventArgs(IQuery query, ObjectInfo objectInfo, ObjectContext context, PersistentOperations operation, PersistDepths persistDepth)
			: this(objectInfo, context, operation, persistDepth)
		{
			if (query == null)
				throw new ArgumentNullException("query");

			_query = query;
		}

		/// <summary>
		/// Returns the <see cref="Opf3.ObjectInfo">ObjectInfo</see> that contains state
		/// informations of the persistent object that implements the
		/// <see cref="IObjectNotification">IObjectNotification</see> interface.
		/// </summary>
		/// <value>
		/// The <see cref="ObjectInfo">ObjectInfo</see> object with the state
		/// information.
		/// </value>
		public ObjectInfo ObjectInfo
		{
			get { return _objectInfo; }
		}

		/// <summary>
		/// Returns the <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </summary>
		/// <value><see cref="ObjectContext">ObjectContext</see> of the current operation.</value>
		public ObjectContext Context
		{
			get { return _context; }
		}

		/// <summary>
		/// Specifies the <see cref="Opf3.Query.IQuery">IQuery</see> of the current operation.
		/// It can be null if the object is not used in the current operation.
		/// </summary>
		/// <value>
		/// The <see cref="Opf3.Query.IQuery">IQuery</see> used
		/// in<see cref="ObjectInfo">ObjectInfo Class</see> the current operation.
		/// </value>
		public IQuery Query
		{
			get { return _query; }
			set { _query = value; }
		}

		/// <summary>
		/// Returns the current <see cref="PersistentOperations">PersistentOperation</see> that is executed
		/// on the persistent object.
		/// </summary>
		public PersistentOperations CurrentOperation
		{
			get { return _operation; }
		}

		/// <summary>
		/// Returns the depth of the <strong>loaded object graph</strong> that is persisted during the current persist process.
		/// </summary>
		public PersistDepths PersistDepth
		{
			get { return _persistDepth; }
		}
	}
}
